package com.cn.整合.SpringBoot.topic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Topic;
import java.util.UUID;

/**
 * @author: dlr
 * @data: 2019/8/21 23:37
 * @desc:SpringBoot整合发布订阅队列生产者
 */
@Component
public class BootMQ_Producer_Topic {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    int count=1;
    @Autowired
    private Topic topic;

    public void sendMsg(){
        System.err.println("发送消息");
        jmsMessagingTemplate.convertAndSend(topic,"msg"+ UUID.randomUUID().toString().substring(0,6));
    }
    /*
     * @author: dlr
     * @desc:   每隔三秒创建一条消息
     * @date: 2019/8/26
     * @param
     * @return: void
     */
    @Scheduled(fixedDelay =3000)
    public void sendMsgByTime(){
        System.err.println("发布订阅定时发送消息"+count++);
        jmsMessagingTemplate.convertAndSend(topic,"msg"+ UUID.randomUUID().toString().substring(0,6));
    }
}
